//
//  ZXFDCCVNav.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/19.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "ZXFDCCVNav.h"

@implementation ZXFDCCVNav

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    [self addSubview:self.backButton];
    [self addSubview:self.titleLabe];
}
- (void)layout{
    [_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@10);
        make.height.equalTo(@24);
        make.width.equalTo(@60);
    }];
    [_titleLabe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.backButton.mas_centerY);
        make.left.equalTo(self.backButton.mas_right);
        make.right.equalTo(self.mas_right);
    }];
}
- (UILabel *)titleLabe{
    if (!_titleLabe) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"创建班级";
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:16];
        label.textAlignment = 1;
        _titleLabe = label;
    }
    return _titleLabe;
}
- (UIButton *)backButton{
    if (!_backButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@" 返回" forState:UIControlStateNormal];
        [button setTitleColor:[UIColorChange colorwithHexString:@"SELECTEDCOLOR"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"back_color"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:SELECTEDCOLOR forState:0];
        [button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
        _backButton = button;
    }
    return _backButton;
}
- (UIButton *)commitButton{
    if (!_commitButton) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:@"提交" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [btn setTitleColor:SELECTEDCOLOR forState:UIControlStateSelected];
        btn.selected = NO;
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        [btn addTarget:self action:@selector(commiteClick:) forControlEvents:UIControlEventTouchUpInside];
        _commitButton = btn;
    }
    return _commitButton;
}
- (void)commiteClick:(UIButton *)sender{
    if (sender.selected == NO) {
        return;
    }else{
        [self.delegate submiteClick];
    }
}
#pragma mark - 添加提交按钮
- (void)addCommitButton{
    [self addSubview:self.commitButton];
    [_commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@0).offset(-20);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@50);
        make.height.equalTo(@30);
    }];
}
- (void)back:(UIButton *)sender{
    [self.delegate backClick];
}
@end
